package com.dayatang.hrm.compensation.integration;

import org.apache.tapestry5.hibernate.HibernateCoreModule;
import org.apache.tapestry5.hibernate.HibernateSessionManager;
import org.apache.tapestry5.ioc.services.TapestryIOCModule;
import org.hibernate.Transaction;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;

import com.dayatang.commons.domain.InstanceFactory;
import com.dayatang.commons.factory.TapestryIocUtils;
import com.dayatang.hrm.compensation.infra.tapestry.SupportModule;

public abstract class AbstractIntegratedTestCase {

	protected Transaction tx;

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		TapestryIocUtils
				.initInstanceProvider(TapestryIOCModule.class,
						HibernateCoreModule.class, AppModule.class,
						SupportModule.class);
	}

	@Before
	public void setUp() throws Exception {
		tx = getTransaction();
	}

	@After
	public void tearDown() throws Exception {
		tx.rollback();
	}

	protected Transaction getTransaction() {
		HibernateSessionManager sessionManager = InstanceFactory
				.getInstance(HibernateSessionManager.class);
		return sessionManager.getSession().beginTransaction();
	}

}
